<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>event-type-add</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	<script type="text/javascript">
	function add(){
		  //提交
		 $.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/event/event-type!save.action", //请求的action
			   data: $("#myform").serialize(), //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
				   if(data == true){
					   var pWin = getTopWin(window).currentWin["add-event-type"];
					   pWin.datagrid();
					   getTopWin(window).closejBox("add-event-type");
				   }
				   
			   }
		});
	  }
		function closewin(){
		  	getTopWin(window).closejBox("add-event-type");
	  	}
		$(function(){
			  $.formValidator.initConfig({formid:"myform"
		          ,onerror:function(msg){}
		          ,onsuccess:function(){
		        	  		add();
		          			return false;
		          }
		          });
			  $("#name").formValidator({onshow:"请输入字符串",onfocus:"请输入字符串",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({min:1,max:64,onerror:"长度非法"})
			  .ajaxValidator({
					type : "post",
					async : false,
					url:'${pageContext.request.contextPath}/event/event-type!checkName.action',
					data: "name="+encodeURI(encodeURI($("#name").val())),
					datatype : "json",
					success : function(data){
						if(data== true)
						{
							return true;
						}else
						{
							return false;
						}
		   			},
				buttons: $("#button"),
				error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
				onerror : "已经存在",
				onwait : "正在校验"
				});
			  $("#desc").formValidator({onshow:"请输入字符串",onfocus:"请输入字符串",oncorrect:"可以为空"}).inputValidator({min:0,max:128,onerror:"长度非法"});
		  });
	</script>
  </head>
  
  <body class="padding-8">
    <form action="" id="myform" name="myform" method="post">
    		<table class="table_eidt">
    			<tr>
	    			<td class="td_left" style="width:70px"><span class="span_alert">*</span>名称</td>
	    			<td class="td_right">
	    				<input id="name" name="name" type="text" class="input_text">
	    				<span id="nameTip" style="width:150px"></span>
					</td>
    			</tr>
    			<tr>
	    			<td class="td_left">事件性质</td>
	    			<td class="td_right"><select name="recoverable" id="recoverable" style="width: 228px">
			          	<option value="1">可恢复</option>
			          	<option value="0">不可恢复</option>
			        </select>
			        </td>
    			</tr>
    			<tr>
	    			<td class="td_left">描述</td>
	    			<td class="td_right">
	    				<textarea id="desc" name="desc" style=" width:266px; height:46px; border:1px solid #c0c0c0;"></textarea>
	    				<span id="descTip" style="width:150px"></span>
	    			</td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:5px;">
	    		<button type="submit" id="button" name="button" class="btn-4">保存</button>
	    		<button type="button" onclick="closewin();" class="btn-4">取消</button>
    		</div>
    		<input type="hidden" name="resId" id="resId" value=${resId}>
    	</form>
  </body>
</html>
